package com.vision.sales.sv.report;

import java.util.HashMap;
import java.util.Map;

import com.vision.sales.cm.db.data.SalesInvoice;

/**
 * 
 * @author Mark
 *
 */
public class SalesInvoiceRow implements Comparable<SalesInvoiceRow> {
	public static final String COLLECTION = "collection";
	public static final String DISCOUNT_OVERPAY = "discOverPay";
	public static final String NET_AMT = "netAmt";
	public static final String COMM_AMT = "commAmt";
	
	private SalesInvoice invoice;
	private Map<String, Double> collectionMap;
	
	public SalesInvoiceRow(SalesInvoice invoice) {
		this.invoice = invoice;
		this.collectionMap = new HashMap<String, Double>();
	}

	@Override
	public int compareTo(SalesInvoiceRow r) {
		return invoice.getInvoiceNo().compareToIgnoreCase((String) r.get("invoice"));
	}

	public Object get(String column) {

		if ("date".equals(column)) return invoice.getDate();
		if ("invoice".equals(column)) return invoice.getGroupAndNo();
		if ("customer".equals(column)) return invoice.getCustomer().getCode();
		if ("sales".equals(column)) return invoice.getGrossSales();
		
		Object d = this.collectionMap.get(column);
		return (d != null) ? d : 0.0;
	}
	
	public void fillRow(String column, Double amount) {
		if (amount == null) amount = 0d;
		
		Double value = this.collectionMap.get(column);
		if (value == null)
			this.collectionMap.put(column, amount);
		else
			this.collectionMap.put(column, value + amount);
	}
}
